package br.com.equus.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import br.com.arquitetura.DAO.UniversalDAO;
import br.com.equus.entidade.Entrada;
import br.com.equus.entidade.ItemEntrada;
import br.com.equus.service.EntradaService;

@Service(value = "entradaService")
@Transactional(readOnly = true, rollbackFor = Exception.class, propagation = Propagation.SUPPORTS)
public class EntradaServiceImpl implements EntradaService {

	@Autowired(required = true)
	@Qualifier(value = "universalDAO")
	protected UniversalDAO dao;

	@Override
	@Transactional(readOnly = false, rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
	public void save(Entrada model) throws Exception {
		for (ItemEntrada item : model.getItensExcluir()) {
			dao.remove(ItemEntrada.class, item.getId());
		}

		dao.save(model);

	}

}
